package cell_2d;

/**
 * @author Cyrille Boulanger
 *
 */
public class cell {
	public static final int NB_NEIGHBORS = 8;
	public enum Directions {
	    NW, N, NE, W, E, SW, S, SE
	}

	/**
	 * The constructor of the cell class
	 * 
	 * @param coord_x
	 * @param coord_y
	 * @param start_status
	 */
	public cell(int coord_x, int coord_y, boolean start_status) { 
		x = coord_x; 
		y = coord_y; 
		status = start_status;
		age = 0;
		for(int i=0; i<NB_NEIGHBORS; i++) {
			neighbors[i] = null;
		}
		
	}
	/**
	 * @return the status of the cell
	 */
	public boolean get_status() { return status; }
	/**
	 * @param new_status the new status of the cell
	 */
	public void set_status(boolean new_status) { status = new_status; }
	/**
	 * @return age
	 */
	public int get_age() { return age; }
	/**
	 * @param new_age
	 */
	public void set_age(int new_age) { age = new_age; }
	/**
	 * Increment the age of the cell by 1 
	 */
	public void increment_age() { age++; }
	/**
	 * Reset the age of the cell 
	 */
	public void reset_age() { age = 0; }
	/**
	 * Add a neighbor
	 * 
	 * @param dir
	 */
	public void add_neighbor(int dir, cell n) { neighbors[dir] = n; }
	/**
	 * Get total number of live neighbors
	 * 
	 * @return the number of live neighbors
	 */
	public int get_num_live_neighbors() {
		int cnt = 0;
		for(Directions d: Directions.values()) {
			if(neighbors[d.ordinal()] != null) {
				if(neighbors[d.ordinal()].get_status() == true) {
					cnt++;
				}
			}
		}
		return cnt;
	}
	
	private int x;
	private int y;
	private	boolean status;
	private int age;
	private cell [] neighbors = new cell[NB_NEIGHBORS]; // Note: cell objects are not created here. 
}
